<%--
  Created by IntelliJ IDEA.
  User: DELL
  Date: 2021/4/1
  Time: 15:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link href="${pageContext.request.contextPath}/css/bootstrap.min.css" type="text/css" rel="stylesheet">
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-3.1.1.min.js"></script>
</head>
<body>

<h1 align="center">邮箱登录</h1>

<form class="form-horizontal">

    <div class="form-group">

        <label class="col-md-4" align="right">邮箱：</label>
        <div class="col-md-4">
            <input type="text" id="name"  class="form-control">
        </div>
    </div>
    <div class="form-group">
        <label class="col-md-4" align="right">验证码：</label>
        <div class="col-md-4">
            <input type="password" id="pwd"  class="form-control">
        </div>
    </div>


    <div class="form-group">
        <label class="col-md-4"></label>
        <div class="col-md-4">
            <input type="button" class="btn btn-success btn-sm" onclick="sendCode()" value="发送验证码">
            <input type="button" class="btn btn-success btn-sm" onclick="login()" value="登录">
            <a href="${pageContext.request.contextPath}/admin/registPage" class="btn btn-success btn-sm">注册</a>
        </div>
    </div>

    <br>
    <span id="info"  style="color:red;position: absolute;left:30%" ></span>


</form>
</body>
<script>
    //发送验证码
    function sendCode() {
        var email  = $("#name").val();
        //ajax请求
        $.ajax({
            url :"${pageContext.request.contextPath}/login/sendCodeAjx",
            type:"post",
            data:{"email":email,},
            contentType: "application/x-www-form-urlencoded",
            dataType:"json",
            success:function (data) {
                console.log(data);
                //alert(data.info);
                $("#info").text(data.info);

            }
        })

    }
    //登录
    function login() {
        //验证吗
        var code  = $("#pwd").val();
        //ajax请求
        $.ajax({
            url :"${pageContext.request.contextPath}/login/email",
            type:"post",
            data:{"code":code,},
            contentType: "application/x-www-form-urlencoded",
            dataType:"json",
            success:function (data) {
                console.log(data);
                //alert(data.info);
                $("#info").text(data.info);
                window.location.href="${pageContext.request.contextPath}/index.jsp";

            }
        })
    }

</script>

</html>
